package 连号区间数;

import java.util.Scanner;

public class Main {
    static int N = 10010;
    static int[] a = new int[N];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }
        int res = 0;
        for (int i = 0; i < n; i++) {
            int max = Integer.MIN_VALUE;
            int min = Integer.MAX_VALUE;
            for (int j = i; j < n; j++) {
                if (a[j] > max) {
                    max = a[j];
                }
                if (a[j] < min) {
                    min = a[j];
                }
                if (max - min == j - i) {
                    res++;
                }
            }
        }
        System.out.println(res);
    }
}
